/**
 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
 *
 * 
 * @param array int整型一维数组 
 * @return int整型一维数组
 */
 function FindGreatestSumOfSubArray( array ) {
  // write code here
  let dp = new Array(array.length)
  dp[0] = array[0]
  let maxSum = array[0]
  let left = 0
  let right = 0
  let resl = 0
  let resr = 0
  for(let i = 1;i < array.length;i++){
    // dp[i] = Math.max(dp[i-1]+array[i],array[i])
    if(dp[i-1]+array[i] >= array[i]){
      right = i
      dp[i] = dp[i-1]+array[i]
    }else{
      left = i
      right = i
      dp[i] = array[i]
    }
    if(dp[i] > maxSum || dp[i] === maxSum && (right - left) > (resr - resl)){
      maxSum = dp[i]
      resl = left
      resr = right
    }
  }
  return array.slice(resl,resr+1)
}
module.exports = {
  FindGreatestSumOfSubArray : FindGreatestSumOfSubArray
};